package com.gaogzhen.intro.commonMethod;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j(topic = "cm.CMPhase2terminationMode")
public class CMPhase2terminationMode {
    public static void main(String[] args) throws InterruptedException {
        Thread monitor = new Thread(() -> {
                while (true) {
                    // 判断是否打断
                    if (Thread.currentThread().isInterrupted()) {
                        log.debug("处理善后");
                        break;
                    }

                    try {
                        // 睡眠
                        TimeUnit.SECONDS.sleep(1);
                        // 监控记录
                        log.debug("监控记录执行...");
                    } catch (InterruptedException e) {
                        // 设置打断标记
                        Thread.currentThread().interrupt();
                        e.printStackTrace();
                    }
                }
        }, "t1");

        log.debug("监控模块开始执行...");
        monitor.start();
        TimeUnit.MILLISECONDS.sleep(3500);
        // 模拟意外打断情况
        monitor.interrupt();
        log.debug("监控模块关闭...");
    }
}
